package bb.lanxing.device.sync

import bb.lanxing.lib.devices.api.ConnectionListener
import bb.lanxing.lib.kt.XossCoroutineScopeKt
import bb.lanxing.model.database.Device
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch

object XossDeviceAutoSyncManager {
    private val listener: ConnectionListener =
        ConnectionListener { smartDevice, i, i2 ->
            run {
                when (i) {
                    2 -> {
                        if (Device.isThisTypeNeedAutoConnect(smartDevice.getType())) {
                            GlobalScope.launch(Dispatchers.Main) {
                                val address = smartDevice.address
                            }
                        }
                    }

                    4 -> {

                    }

                    8 -> {

                    }
                }
            }
        }
    private val tasks: Array<XossDeviceAutoSyncTask?> = arrayOfNulls(0)
    private val timerTasks: Array<XossDeviceAutoSyncTimerTask?> =
        arrayOfNulls<XossDeviceAutoSyncTimerTask>(0)

    fun refreshTimerTask(address: String, name: String, i: Int) {
        XossCoroutineScopeKt.getXossCoroutineScope().launch(Dispatchers.Main) {
            onTimerTaskGo(address, name, i)
        }
    }

    fun onTimerTaskGo(address: String, name: String, i: Int) {
//        val len = timerTasks.size

    }
}